package com.bhh.myservlet;

import lombok.extern.slf4j.Slf4j;

import java.io.File;

/**
 * @author bhh
 * @description 工具类
 * @date Created in 2021-04-15 9:20
 * @modified By
 */
@Slf4j
public class Util {
    // 文件分隔符 + 路劲
    public static final String WEB_ROOT = System.getProperty("user.dir") + File.separator + "webroot";

    public static final String PROTOCOL = "HTTP/1.1";

    public static final String CARRIAGE = "\r";

    public static final String NEWLINE = "\n";

    public static final String SPACE = " ";

    /**
     * 格式 : HTTP/1.1 200 OK /r /n /r /n
     * @param status
     * @return
     */
    public static String renderStatus(HttpStatus status) {
        StringBuilder str = new StringBuilder(PROTOCOL)
                .append(SPACE)
                .append(status.getStatusCode())
                .append(SPACE)
                .append(status.getReason())
                // 做格式间隔
                .append(CARRIAGE).append(NEWLINE)
                .append(CARRIAGE).append(NEWLINE);

        return str.toString();
    }
}
